﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RWLib
{
    class SometimesExecutableQuery : Query
    {

        private Scenario sc;

        public SometimesExecutableQuery(Tree _tree)
        {
            tree = _tree;
        }

        public SometimesExecutableQuery(Tree _tree, Scenario _sc)
        {
            tree = _tree;
            sc = _sc;
        }

        override public bool Run()
        {
            List<Node> children = tree.Root.Nodes;
            while (children.Count>0)
            {
                if (children.Any(c => sc.ActionsNames.ContainsKey(c.t) && sc.ActionsNames[c.t].Except(c.actions.Select(a => a.Name).ToArray()).Count() == 0))
                {
                    return true;
                }
                children = children.Select(c => c.Nodes).SelectMany(c => c).ToList();
            }
            return false;
        }

    }

}
